<?php


class lieu extends base{

  CONST CLASS_NAME  = 'lieu';
  CONST TABLE_NAME  = 't_lieux';
  CONST PRIMARY_KEY = 'lieu_id';

  var $lieu_id; 	
  var $lieu_nom;
  var $lieu_diminutif;
  var $lieu_adresse;
  var $lieu_plan_URL;
  var $lieu_site_URL;
  
  public function getTableName() {
    return self::$TABLE_NAME;
  }

  public function getClassName() {
    return self::$CLASS_NAME;
  }

  public function getPrimaryKey() {
    return self::$PRIMARY_KEY;
  }  

  /**
   *
   * @param type $array
   * @return lieu
   */
  
  public function __construct($array) {
    parent::__construct($array);
    return $this;
  }
  
  /**
   *
   * @param int $id
   * @param string $by
   * @param string $order_by
   * @return lieu or array
   */
  
  public static function getLieu($id=0,$by='',$order_by=''){
    $db = base::getDb();

    $sql =  "select * from t_lieux as t_l";

    if($id!=0){
      $sql = sprintf("$sql where lieu_id=%d",$id);
    }

    if($order_by!=''){
      $sql = sprintf("$sql order by %s",$order_by);
    }

    if($by!=''){
      $ret = $db->SelectAllBy($sql, $by);
    } else {
      $ret = $db->SelectAll($sql);
    }  

    if($id!=0){
      if(is_array($ret) && isset($ret[0])){
      $ret = new lieu($ret[0]);
      } else {
        $ret='';
      }
    } else {
      $ret2 = array();
      foreach($ret as $lieu){
        $ret2[] = new lieu($lieu);
      }
      $ret=$ret2;
    }

    return $ret;

  }
  

}

